#include <algorithm>
#include <iostream>
#include <ios>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

int main() 
{ 
	//TODO
	//输入姓名
	cout<<"Please enter your name:";
	string name;
	cin>>name;
	cout<<"Hello, "<<name<<"!"<<endl;

	//输入期中期末成绩
	int midterm,final;
    cout<<"Please enter you midterm and final exam grades:";
	cin>>midterm>>final;

	
	cout<<"Enter all your homework grades, followed by end-of-file:";
	int nextGrade;
	vector<int> homework;
	while (cin>>nextGrade){
		homework.push_back(nextGrade);
		if(cin.get() == '\n') break;
	}
	sort(homework.begin(),homework.end());
	//中位数成绩
	double median;
	int size=homework.size();
	if (size%2==0){
		median=(homework[size/2]+homework[size/2-1])/2.0;
	}
	else median=homework[size/2];

	double grade=0.4*final+0.2*midterm+0.4*median;
	cout.setf(ios::fixed);
	cout<<setprecision(1);
    
	cout<<"Your final grade is "<<grade<<endl;
	cout<<"Press any key to continue"<<endl;
   
	return 0; 
} 
